const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
const path = require('path');
const router = require('./router');
const http = require('http');
const errorHandler = require('./middleware/error-handler');
const createWebSocketServer = require('./websocket/index')
require('./model');
const app = express();
const server = http.createServer(app);
const wss = createWebSocketServer(server);
app.use(cors());
app.use(morgan('dev'));
app.use(express.json());
// app.use('/upload', express.static(path.join(__dirname, 'upload')));
app.use('/api', router);
app.use(errorHandler());
// 启动 3000 端口的 HTTP 服务器
server.listen(3000, () => {
    console.log('启动成功');
});
